<template>
    <div class="clinicPayment">
        <!-- clinicPayment -->
        <header>
            <Row>
                <Col>
                    <div class="margin-up-down">
                        <span>开始日期</span>
                        <DatePicker type="date" v-model="getParams.startDate" style='width:120px;'></DatePicker>
                    </div>
                    <div class="margin-up-down">
                        <span>结束日期</span>
                        <DatePicker type="date" v-model="getParams.endDate" style='width:120px;'></DatePicker>
                    </div>
                    <div class="margin-up-down">
                        <Button type='success' @click='query()'>查询</Button>
                    </div>
                </Col>
            </Row>
        </header>
        <Table stripe :row-class-name="rowClassName" :columns="columns1" :data="data1" style='margin:10px 0;'></Table>
        <div class="page">
            <Page :total="count" :current='pageNo' :page-size="pageSize" show-total show-elevator @on-change="pageChange"/>
        </div>
    </div>
</template>
<script>
import api from "@/api/commonApi";
import { DatePicker, TimePicker, Card, Progress } from 'view-design'
// 诊间交费
export default {
    components: {
        DatePicker,
        TimePicker,
        Card,
        Progress
    },
    data () {
        return {
          ORDER_TYPE_ENUM:[
            {code:0,name:'健康咨询'},
            {code:1,name:'巡诊'},
            {code:2,name:'复诊'},
            {code:3,name:'续方'},
            {code:4,name:'用药咨询'},
            {code:5,name:'购药'},
            {code:6,name:'预约挂号'},
            {code:7,name:'家医签约'},
            {code:8,name:'远程门诊'},
            {code:9,name:'直播'},
            {code:10,name:'点播'},
            {code:11,name:'诊间缴费'},
            {code:12,name:'充值'},
            {code:13,name:'住院押金缴费'},
            {code:14,name:'院后随访'},
            {code:15,name:'外延处方'},
            {code:16,name:'远程会诊'},
            {code:17,name:'病历复印'},
            {code:18,name:'检查检验预约'},
            {code:19,name:'检查预约'},
            {code:20,name:'检验预约'},
            {code:21,name:'体检预约'},
            {code:22,name:'互联网缴费'},
            {code:23,name:'手术预约'},
            {code:30,name:'线上就诊'}
          ],

          // 头部参数
            getParams: {
                // 开始时间
                startDate: '',
                startTime: "00:00",
                // 结束时间
                endDate: "",
                endTime: "",
                // 查询条件
                searchKey:"",
                // 异常
                single : false,
            },
            // 列表数据
            columns1: [
                {
                    key: "isum",
                    title: "排序",
                    align: "center",
                    width:60,
                    render: (h, params) => {
                        let isum = (this.pageNo-1)*this.pageSize + params.index +1;
                        return h("span", isum);
                    }
                },
                {
                    key: "dataTime",
                    title: "账单日期",
                    align: "center"
                },
                {
                    key: "deptName",
                    title: "科室",
                    align: "center"
                },
                {
                    key: "doctorName",
                    title: "医生",
                    align: "center"
                },
                {
                    key: "itemType",
                    title: "类别",
                    align: "center",
                    render: this.findTypeName
                },
                {
                    key: "sumsMoney",
                    title: "金额",
                    align: "center"
                },
            ],
            data1: [],
            // 分页数据
            count: 0,
            pageNo: 1,
            pageSize: 10,
            // 弹窗状态
            clinicStatus: false,
            // 单个平台状态列表
            statusList: ['失败','交易成功','退费', '未获取到状态'],
            //支付渠道
            Channels:['微信','支付宝','线下支付','就诊卡号','医保支付'],
            // 点击来源
            buttonStatus: 1,
            orderStatusList: [
                {
                    name: "支付成功",
                    id:'1'
                },
                {
                    name: "未支付",
                    id:'2'
                },
                {
                    name: "支付失败",
                    id:'3'
                },
                {
                    name: "支付取消",
                    id:'4'
                },
                {
                    name: "已退费",
                    id:'5'
                },
            ],
            
            // // 自动对账状态
            autoLoad:false,
            // 进度条
            progressStart: 0,
            uuid :'',
            DZdisabled: false,
        }
    },
    created () {
        this.getParams.startDate = this.GetDate(0);
        this.getParams.endDate = this.GetDate(0);
    },
    mounted () {
        this.loadingCardRechargeList(this.pageNo)
    },
    methods: {
        findTypeName(h, params) {
          let record = params.row;
          console.log("params===============",params)
          let typeName = "";
          //找到名字
          for(let i=0;i<this.ORDER_TYPE_ENUM.length;i++){
            if( this.ORDER_TYPE_ENUM[i].code==record.itemType){
              typeName = this.ORDER_TYPE_ENUM[i].name;
              break;
            }
          }
          if(typeName==""){
            typeName = "未知类型-"+record.businessType;
          }
          return [
            h("span", typeName)
          ]
        },
        query () {
          this.loadingCardRechargeList(this.pageNo)
        },
        // 分页器改变
        pageChange (index) {
            this.pageNo = index;
            // this.loadingCardRechargeList(index)
            this.query(index)
        },

        // 加载页面列表数据
        loadingCardRechargeList (pageNo) {
            /*
                加载页面列表对账信息
            */
            this.pageNo = pageNo
            let url = api.statFinanceDoctor
            let start = this.getData(this.getParams.startDate);
            let end = this.getData(this.getParams.endDate);
            let params = {
                pageNo: pageNo,
                pageSize: this.pageSize,
                startDate: start,
                endDate: end
            }
            
            if(this.getParams.startDate === '' || this.getParams.startDate === null){
                delete params.startTime
            }
            if(this.getParams.endDate === '' || this.getParams.endDate === null){
                delete params.endTime
            }

            this.$axios.post(url,params).then(ress => {
                if(ress.data.success) {
                    let ret = ress.data.object;
                    this.count = ret.total
                    console.log(ret);
                    if(ret.records){
                        ret.records.forEach((item, index) => {
                            item.isum = this.addZeros(index)
                        })
                        this.data1 = ret.records
                    } else {
                        this.data1 = []
                    }
                } else {
                    this.$Message.info("请确认当前账号是否绑定机构")
                }
            })
        },
        // 显示异常数据
        rowClassName (row, index) {
            if(Number(row.checkingStatus) == 0) {
                return ''
            } else if (row.tradingChannels >= 0) {
                // console.log('row.tradingChannels', row.tradingChannels)
                if(row.tradingChannels == 3) {
                    // 当支付渠道为就诊卡时只使用 支付平台与His对账的状态区分显示样式
                    if(row.platformHisStatus != 1) {
                        return 'demo-error-row';
                    } else {
                        return 'demo-success-row'
                    }
                    // 支付渠道为其他状态时 使用三个对比状态进行区分显示样式
                } else if(row.platformHisStatus != 1 || row.thirdHisStatus != 1 || row.platformThirdStatus != 1) {
                    console.log('hhhhhhhhhhhhhh')
                    return 'demo-error-row';
                }
            } else if(Number(row.checkingStatus) == 1) {
                return 'demo-success-row'
            }
            return '';
        },
        // 转换日期格式
        getData(data){
            let datas = new Date(data)
            var curr_date = datas.getDate();
            var curr_month = datas.getMonth() + 1;
            var curr_year = datas.getFullYear();
            function add(num){
                if(Number(num)<10) {
                    return '0' + num
                }
                return num
            }
            return curr_year + "-" + add(curr_month)+'-' + add(curr_date)
        }
    }
};
</script>

<style lang="less" scoped>
.clinicPayment {
    width: calc(100%);
    padding: 10px 30px;
    margin: 0 auto;
    background: #fff;
    .margin-up-down {
        display: inline-block;
        margin-top: 10px;
    }
    .page{
        text-align: center;
        margin-top: 20px;
    }
}
</style>
<style>
.ivu-table .demo-error-row td{
    color: red;
}
.ivu-table .demo-error-row td a{
    color:red
}
.ivu-table .demo-success-row td{
    color: #2b85e4;
}
.ivu-table .demo-success-row td a{
    color:#2b85e4
}
</style>
